package com.weather.job;

import org.quartz.*;
import org.springframework.context.annotation.Bean;

/**
 * QuartzJob定时任务配置
 * @author: htc
 * @date: Created in 16:27 2018/5/4.
 */
//@Configuration
public class QuartzConfiguration {
    @Bean
    public JobDetail jobDetail() {
        return JobBuilder.newJob(WeatherDataSyncJob.class)
                .withIdentity("weatherDataSyncJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger trigger(){
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                //1800秒执行一次
                .withIntervalInSeconds(1800)
                //重复
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(jobDetail())
                .withIdentity("weatherDataSyncTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
